﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace GameSPK
{
    public class OChu
    {
        public string ChuDeOChu 
        { set; get; }
        public string DapAnOChu 
        { set;
            get; 
        }
        public int SoOHangNgang { set; get; }
        private string DapAnOChuConLai { set; get; }
        public List<HangNgang> OChuHangNgang { set; get; }
        public HangNgang this[int index]
        {
            get
            {
                return OChuHangNgang.ElementAt(index);
            }
            set
            {
                this.OChuHangNgang.Add(value);
            }
        }
        public OChu()
        {
            this.OChuHangNgang = new List<HangNgang>();
        }
        public void SaveXML(String filename)
        {
          
            var layout = new XElement("CrossWordContent",
                new XElement("CrossWord",
                    new XAttribute("ChuDe", ChuDeOChu),
                    new XAttribute("DapAn", DapAnOChu),
                    new XAttribute("SoHangNgang", SoOHangNgang)
                 )
                 );

            var hangngang = new XElement("HangNgang"

                );
            for (int i = 0; i < SoOHangNgang; i++)
            {
                XElement cau = new XElement("HangNgang" + i,
                    new XAttribute("CauHoi", this[i].CauHoi),
                    new XAttribute("OHangNgang", this[i].DapAn),
                    new XAttribute("KeyChar",new String(this[i].KeyChar))
                    );
                hangngang.Add(cau);
            }

            layout.Add(hangngang);
            layout.Save(filename);
        }
        public void ReadXML(String folder)
        {
        }
    }
    public class HangNgang
    {
        public string CauHoi { set; get; }
        public string DapAn { set; get; }
        public char[] KeyChar { set; get; }
    }
}
